/*
 * @Description: 路由
 * @Author: lwx
 * @Date: 2022-11-07 14:14:29
 * @LastEditors: lwx
 * @LastEditTime: 2023-04-12 11:30:06
 */
import Vue from "vue";
import Router from "vue-router";
import Layout from "@/views/layout/Layout";

Vue.use(Router);

//不需要动态判断权限的路由
export const constantRouterMap = [{
        path: "/redirect",
        component: Layout,
        hidden: true,
        children: [{
            path: "/redirect/:path*",
            component: () =>
                import ("@/views/redirect/index"),
        }, ],
    },
    {
        path: "",
        redirect: "/login",
        hidden: true,
    },
    {
        path: '/dashboard',
        name: 'dashboard',
        component: () =>
            import ("@/views/dashboard/index"),
        children: [{
            path: "index",
            component: () =>
                import ("@/views/dashboard/index"),
            meta: {
                title: "看板",
                icon: "dashboard",
            },
        }]
    },

    {
        path: "/login",
        component: () =>
            import ("@/views/login/index"),
        hidden: true,
    },

    {
        path: "/404",
        component: () =>
            import ("@/views/errorPage/404"),
        hidden: true,
    },
];
//实例化vue的时候只挂载constantRouter
export default new Router({
    // scrollBehavior: () => ({
    //     y: 0,
    // }),
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { x: 0, y: 0 }
        }
    },
    routes: constantRouterMap,
});

//需求动态判断权限并通过 addRouters 动态添加的页面
export const asyncRouterMap = [{
        path: "/emp",
        name: "emp",
        component: Layout,
        meta: {
            icon: 'yuangongguanli_1',
            roles: ['系统管理员']
        },
        children: [{
            path: "employee",
            name: 'Employee',
            component: () =>
                import ("@/views/employee/Employee"),
            meta: {
                title: '人员管理',
                roles: ['系统管理员']
            },
        }, ],
    },
    {
        path: "/dev",
        name: "dev",
        component: Layout,
        meta: {
            title: "设备管理",
            icon: "jiankong",
        },
        children: [{
                path: "list",
                name: "DeviceList",
                component: () =>
                    import ("@/views/device/DeviceList"),
                meta: {
                    title: "设备列表",
                },
            }, {
                path: "repair",
                name: "DeviceRepair",
                component: () =>
                    import ("@/views/device/DeviceRepair"),
                meta: {
                    title: "设备维修",

                },
                hidden: true
            },
            {
                path: "params",
                name: "DeviceParams",
                component: () =>
                    import ("@/views/params/DeviceParams"),
                meta: {
                    title: "设备详情",
                },
                hidden: true
            },
            {
                path: "repairRecord",
                name: "RepairRecord",
                component: () =>
                    import ("@/views/device/RepairRecord"),
                meta: {
                    title: "维修记录",

                },
            },
            {
                path: "maintainRecord",
                name: "MaintainRecord",
                component: () =>
                    import ("@/views/device/MaintainRecord"),
                meta: {
                    title: "保养记录",

                },
            },
        ],
    },
    {
        path: "/pro",
        name: "pro",
        component: Layout,
        meta: {
            title: "生产管理",
            icon: "dingdan",
        },
        children: [{
                path: "order",
                name: 'Order',
                component: () =>
                    import ("@/views/order/Order"),
                meta: { title: '订单管理', affix: true },

            },
            {
                path: "task",
                name: 'Task',
                component: () =>
                    import ("@/views/task/OrderTask"),
                meta: { title: '任务管理' },
            },
            {
                path: "product",
                name: 'Product',
                component: () =>
                    import ("@/views/product/Product"),
                meta: { title: '产品管理' },
            },
            {
                path: "sop",
                name: 'Sop',
                component: () =>
                    import ("@/views/sop/Sop"),
                meta: { title: 'sop' },
                hidden: true,
            },
        ],
    },
    {
        path: "/taskBoard",
        name: "taskBoard",
        component: () =>
            import ("@/views/task/TaskBoard"),
        children: [{
            path: "todayBoard",
            name: 'TodayBoard',
            component: () =>
                import ("@/views/task/TaskBoard"),
            meta: { title: '排班表', icon: 'table' },
        }, ],
    },
    // {
    //     path: "/sto",
    //     name: "/sto",
    //     component: Layout,
    //     meta: {
    //         title: '立库管理',
    //         icon: 'store'
    //     },
    //     children: [{
    //         path: "store",
    //         name: 'Store',
    //         component: () =>
    //             import ("@/views/store/Store"),
    //         meta: { title: '立库' },
    //     }, {
    //         path: "history",
    //         name: 'History',
    //         component: () =>
    //             import ("@/views/store/History"),
    //         meta: { title: '历史记录' },
    //     }, ],
    // },
    {
        path: "/his",
        name: "his",
        component: Layout,
        meta: {
            title: '记录追溯',
            icon: 'search'
        },
        children: [{
                path: "orderBack",
                name: 'OrderBack',
                component: () =>
                    import ("@/views/order/Order"),
                meta: { title: '订单追溯', },
            },
            {
                path: "taskOver",
                name: 'TaskOver',
                component: () =>
                    import ("@/views/task/TaskOver"),
                meta: { title: '任务追溯', },
                hidden: true
            },
            {
                path: "report",
                name: 'Report',
                component: () =>
                    import ("@/views/report/Report"),
                meta: { title: '产品报表' },
            },
        ],
    },
    {
        path: "/fake",
        name: "fake",
        component: Layout,
        meta: {
            icon: 'xitong',
            roles: ['系统管理员']
        },
        children: [{
            path: "index",
            name: 'index',
            component: () =>
                import ("@/views/fake"),
            meta: {
                title: '数据设置',
                roles: ['系统管理员']
            },
        }, ],
    },
    //404一定要放在最后
    {
        path: "*",
        redirect: "/404",
        hidden: true,
    },
];